﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RIS.TMP.WEB.APP.Models;
using RIS.TMP.WEB.APP.AddMigrations;

namespace RIS.TMP.WEB.APP.Controllers
{
    public class CCheckPlanController : Controller
    {
        private AllContext db = new AllContext();

        //
        // GET: /CCheckPlan/

        public ActionResult Index()
        {
            return View(db.CCheckPlans.Where(x => x.RecordStatus == "U").ToList());
        }

        //
        // GET: /CCheckPlan/Details/5

        public ActionResult Details(int id = 0)
        {
            CCheckPlan ccheckplan = db.CCheckPlans.Find(id);
            if (ccheckplan == null)
            {
                return HttpNotFound();
            }
            return View(ccheckplan);
        }

        //
        // GET: /CCheckPlan/Create

        public ActionResult Create()
        {
            return View();
        }

        //
        // POST: /CCheckPlan/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(CCheckPlan ccheckplan)
        {
            if (ModelState.IsValid)
            {
                ccheckplan.RecordStatus = "U";
                ccheckplan.CreateBy = Session["LogedId"].ToString();
                ccheckplan.CreateWhen = DateTime.Now;
                db.CCheckPlans.Add(ccheckplan);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(ccheckplan);
        }

        //
        // GET: /CCheckPlan/Edit/5

        public ActionResult Edit(int id = 0)
        {
            CCheckPlan ccheckplan = db.CCheckPlans.Find(id);
            if (ccheckplan == null)
            {
                return HttpNotFound();
            }
            return View(ccheckplan);
        }

        //
        // POST: /CCheckPlan/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(CCheckPlan ccheckplan)
        {
            if (ModelState.IsValid)
            {
                db.Entry(ccheckplan).State = EntityState.Modified;
                ccheckplan.UpdateBy = Session["LogedId"].ToString();
                ccheckplan.UpdateWhen = DateTime.Now;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(ccheckplan);
        }

        //
        // GET: /CCheckPlan/Delete/5

        public ActionResult Delete(int id = 0)
        {
            CCheckPlan ccheckplan = db.CCheckPlans.Find(id);
            if (ccheckplan == null)
            {
                return HttpNotFound();
            }
            return View(ccheckplan);
        }

        //
        // POST: /CCheckPlan/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            CCheckPlan ccheckplan = db.CCheckPlans.Find(id);
            db.Entry(ccheckplan).State = EntityState.Modified;
            ccheckplan.RecordStatus = "D";
            ccheckplan.UpdateBy = Session["LogedId"].ToString();
            ccheckplan.UpdateWhen = DateTime.Now;
            //db.CCheckPlans.Remove(ccheckplan);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}